package com.travel.travel_springboot_web.controller;

import com.travel.travel_springboot_web.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class HomeController {
    
    @Autowired
    private UserMapper userMapper;
    
    @GetMapping("/")
    public String home() {
        return "Welcome to Travel Application!";
    }
    
    @GetMapping("/test")
    public String test() {
        return "API is working!";
    }
    
    @GetMapping("/users")
    public Object getAllUsers() {
        try {
            return userMapper.findAll();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }
} 